package com.lzcu.maoyan.maoyanweb.util;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @author WangLiang
 * @date `2024/4/22`
 */
@Configuration
public class DataSourceConfig {

    @Bean
    @Primary
    public DataSource dataSource() {
        HikariDataSource dataSource = DataSourceBuilder.create()
                .type(HikariDataSource.class)
                .driverClassName("org.apache.phoenix.jdbc.PhoenixDriver")
                .url("jdbc:phoenix:192.168.2.109,192.168.2.110,192.168.2.112:2181")
                .build();

        // 设置Phoenix的特定属性
        dataSource.addDataSourceProperty("phoenix.schema.isNamespaceMappingEnabled", "true");

        return dataSource;
    }
}

